package middle;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.locks.ReentrantLock;
import middle.Solution_341.IntegerC;

public class Solution_156 {

    public static void main(String[] args) {
//        ReentrantLock lock = new ReentrantLock();
//        lock.lock();
//        lock.unlock();
//        ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
//        map.put(1, 1);
//        map.remove(1);
//        Solution_156 model = new Solution_156();
//        TreeNode root = new TreeNode(1);
//        root.left = new TreeNode(2);
//        root.left.left = new TreeNode(4);
//        root.left.right = new TreeNode(5);
//        root.right = new TreeNode(3);
//        model.upsideDownBinaryTree(root);
//        System.out.println();
    }

    private TreeNode rst = null;
    public TreeNode upsideDownBinaryTree(TreeNode root) {
        rst = null;
        dps(root);
        return rst;
    }

    private void dps(TreeNode node) {
        if (node == null) {
            return;
        } else if (node.left == null) {
            rst = node;
            return;
        }
        dps(node.left);
        TreeNode root = node.left;
        root.right = node;
        root.left = node.right;
        node.left = null;
        node.right = null;
    }

    static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
}
